import { SwaggerRouter } from 'koa-swagger-decorator-fork';
import koaBody from 'koa-body'

const koaRouterOpts = { prefix: '/api/v2' };
const swaggerRouterOpts = {
    title: 'CMAP API V2 Server',
    description: 'API DOC',
    version: '1.0.0',
    swaggerConfiguration: {
        display: {
            defaultModelsExpandDepth: 4,
            defaultModelExpandDepth: 3,
            docExpansion: 'list',
            defaultModelRendering: 'model'
        }
    }
};

const router = new SwaggerRouter(koaRouterOpts, swaggerRouterOpts);
const bodyOptions = {
    jsonLimit: '100mb',
    formLimit: '100mb',
    textLimit: '100mb',
    parsedMethods: ['POST', 'PUT', 'PATCH', 'DELETE'],
    multipart: true,
    formidable: {
        uploadDir: './attachments'
    }
}
router.use(koaBody(bodyOptions))

// swagger docs avaliable at http://localhost:3000/api/v2/swagger-html
router.swagger();

// mapDir will scan the input dir, and automatically call router.map to all Router Class
router.mapDir(__dirname, {
    recursive: true,
    doValidation: true,
});

export default router;
